<template>
	<view class="rebate">
		<uni-card  :is-shadow="false" :border="false" :margin="'0 20rpx'" :spacing="'20rpx'" :padding="0">
			<template v-slot:title>
				<view class="title">
					<text class="text">退款</text>
				
					<uni-easyinput :clearable="false" v-if="id == 1" class="text" type="number" v-model="tui_price" placeholder="请输入退款金额"></uni-easyinput>
					<text v-else class="text">可退保证金￥{{balance || '0.00'}}</text>
				</view>
			</template>
			<uni-easyinput :clearable="false" type="textarea" v-model="content" placeholder="请输入退款理由"></uni-easyinput>
		</uni-card>
		<view class="pay-but">
			<button class="but" plain @click="submit(content)">提交申请</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				content:'', //退款理由
				id:'', // id = 1 余额退款  id = 2 酒店保证金退款  id = 3 保洁保证金退款
				balance:'', // 余额
				tui_price:0, // 余额
				hotel_id: '',
				openid:''
			};
		},
		onLoad(option) {
			this.id = option.id
			this.balance = option.price
			this.hotel_id = option.hotel_id
			this.openid = option.openid
		},
		methods:{
			async submit(val) {
				let _this = this
				let res = ''
				try{
					if(_this.tui_price <= 0 &&  _this.id == 1) {
						uni.showToast({
							title: '请输入退款金额！',
							icon: 'none',
						});
						return
					}else if(_this.balance <= 0 ) {
						uni.showToast({
							title: '没有可退金额！',
							icon: 'none',
						});
						return
					}else if(val == ''){
						uni.showToast({
							title: '退款理由不能为空',
							icon: 'none',
						});
						return
					}
					else{
						if(_this.id == 1) {
							res = await this.$http.post('/index/Hotelrecharge/refund_order',{content:val,hotel_id:_this.hotel_id,tui_price:_this.tui_price})
						}else if (this.id == 2) {
							res = await this.$http.post('/index/Hotelrecharge/refund_bond_order',{content:val,hotel_id:_this.hotel_id})
						}else if (this.id == 3) {
							res = await this.$http.post('/index/Cleanerindex/refund_bond_order',{content:val,openid:_this.openid})
						}
						await uni.showToast({
							title:"申请成功",
							icon:"none"
						})
						this.balance = 0
						this.content = ''
						setTimeout(()=>{
							uni.navigateBack({
							    delta: 1
							});
						},1000)
					}
				}catch(e){
					//TODO handle the exception
					uni.showToast({
						title:e.errMsg,
						icon:"none"
					})
				}
				
			}
		}
	}
</script>

<style lang="scss">
.rebate {
	position: relative;
	box-sizing: border-box;
	padding: 20rpx 0;
	height: 100vh;
	.uni-card {
		border-radius: 20rpx;
	}
	.title {
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom:1rpx solid #EDEDED;
		margin-bottom: 40rpx;
		.text {
			font-size: 28rpx;
			color: #000000;
			margin-bottom: 20rpx;
		}
		.uni-easyinput__content-input {
			text-align: right;
		}
	}
	.uni-easyinput {
		margin-bottom: 20rpx;
		.is-input-border {
			border-radius: 20rpx;
		}
		.uni-easyinput__content-textarea {
			font-size: 28rpx;
			color: #000000;
			height: 300rpx;
			
		}
	}
	.pay-but {
		position: absolute;
		bottom: 40rpx;
		left: 0;
		width: 100%;
		height: 80rpx;
	
		.but {
			color: #FFFFFF;
			background: linear-gradient(-90deg, #8dc9f1, #d8eefc);
			border-radius: 40rpx;
			line-height: 80rpx;
			border: 0;
			margin: 0 20rpx;
		}
	}
}
</style>
